package dao

import (
	"context"
	"gorm.io/gorm"
)

var ErrRecordnotFound = gorm.ErrRecordNotFound

// Tag 标签创建者
type Tag struct {
	Id   int64  `gorm:"primaryKey,autoIncrement"`
	Name string `gorm:"type:varchar(64)"`
	Uid  int64  `gorm:"index"`

	Utime int64
	Ctime int64
}

// TagBiz 某个人对某个资源打了标签
type TagBiz struct {
	Id    int64  `gorm:"primaryKey,autoIncrement"`
	BizId int64  `gorm:"index:biz_id"`
	Biz   string `gorm:"index:biz_id"`
	// 冗余字段，加快查询和删除
	Uid int64 `gorm:"index"`
	Tid int64

	Tag   *Tag `gorm:"ForeignKey:Tid;AssociationForeignKey:Id;constraint:OnDelete:CASCADE"`
	Utime int64
	Ctime int64
}
type TagtDao interface {
	CreateTag(ctx context.Context, tag Tag) (int64, error)
	CreateTagBiz(ctx context.Context, tagBiz []TagBiz) error
	GetTagsByUid(ctx context.Context, uid int64) ([]Tag, error)
	GetTagsByBiz(ctx context.Context, uid int64, biz string, bizId int64) ([]Tag, error)
	GetTags(ctx context.Context, offset, limit int) ([]Tag, error)
	GetTagsById(ctx context.Context, ids []int64) ([]Tag, error)
}

func (Tag) TableName() string {
	return "tag"
}
func (TagBiz) TableName() string {
	return "tag_biz"
}
